﻿using System;
using System.Web.Services;
using Monkey.Warrenty.Biz;
using Monkey.Warrenty.EntityModel;

namespace MonkeyWarranty.Web.Dealers
{
    public partial class List : System.Web.UI.Page
    {
        #region Properties

        private static DealerBiz _dealerBiz;
        private static DealerBiz DealerManager
        {
            get { return _dealerBiz ?? (_dealerBiz = new DealerBiz()); }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var groups = DealerManager.GetAllDealerGroups();
                groups.Insert(0, new DealerGroup{ Id = 0, Name = Resources.GlobalStrings.AllGroups });

                ddlDealerGroups.DataTextField = "Name";
                ddlDealerGroups.DataValueField = "Id";
                ddlDealerGroups.DataSource = groups;
                ddlDealerGroups.DataBind();
            }
        }

        #region Dealer methods

        [WebMethod(EnableSession = true)]
        public static object DealerListByFilter(string name, int dealerGroupId, int jtStartIndex, int jtPageSize, string jtSorting)
        {
            return DealerManager.DealerListByFilterWs(name, dealerGroupId, jtStartIndex, jtPageSize, jtSorting);
        }

        [WebMethod(EnableSession = true)]
        public static object CreateDealer(Dealer record)
        {
            return DealerManager.CreateDealerWs(record);
        }

        [WebMethod(EnableSession = true)]
        public static object UpdateDealer(Dealer record)
        {
            return DealerManager.UpdateDealerWs(record);
        }

        [WebMethod(EnableSession = true)]
        public static object DeleteDealer(int Id)
        {
            return DealerManager.DeleteDealerWs(Id);
        }

        #endregion

        #region DealerGroup methods

        [WebMethod(EnableSession = true)]
        public static object GetDealerGroupOptions()
        {
            return DealerManager.GetDealerGroupOptionsWs();
        }

        #endregion
    }
}